import shelve
d = shelve.open('shelve_test')

class test(object):
    def __init__(self,n):
        self.n = n

t = test(123)
t2 = test(234234)

name = ["alex", "rain", "test"]
d["test"] = name  # 持久化列表
d["t1"] = t  # 持久化类
d["t2"] = t2

d.close()